<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The MongoBinData class</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="mongoregex.tostring.html">« MongoRegex::__toString</a></li>
      <li style="float: right;"><a href="mongobindata.construct.html">MongoBinData::__construct »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="mongo.types.html">Types</a></li>
    <li>The MongoBinData class</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.mongobindata" class="reference">

 <h1 class="title">The MongoBinData class</h1>
 

 <div class="partintro"><p class="verinfo">(PECL mongo &gt;= 0.8.1)</p>

  <div class="warning"><strong class="warning">Warning</strong>
   <p class="para">This extension that defines this class
is deprecated. Instead, the <a href="" class="link">MongoDB</a> extension should be used.
Alternatives to this class include:</p>
   <ul class="simplelist">
    <li class="member"><strong class="classname">MongoDB\BSON\Binary</strong></li>
   </ul>
  </div>


  <div class="section" id="mongobindata.intro">
   <h2 class="title">Introduction</h2>
   <p class="para">
    An object that can be used to store or retrieve binary data from the database.
   </p>
   <p class="para">
    The maximum size of a single object that can be inserted into the database
    is 16MB. For data that is larger than this (movies, music, Henry Kissinger&#039;s
    autobiography), use <a href="class.mongogridfs.html" class="classname">MongoGridFS</a>. For data that is
    smaller than 16MB, you may find it easier to embed it within the document
    using <strong class="classname">MongoBinData</strong>.
   </p>
   <p class="para">
    For example, to embed an image in a document, one could write:
   </p>
   <div class="example" id="mongobindata.intro-example">
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$profile&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"username"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"foobity"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"pic"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoBinData</span><span style="color: #007700">(</span><span style="color: #0000BB">file_get_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">"gravatar.jpg"</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">MongoBinData</span><span style="color: #007700">::</span><span style="color: #0000BB">GENERIC</span><span style="color: #007700">),<br />);<br /><br /></span><span style="color: #0000BB">$users</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">save</span><span style="color: #007700">(</span><span style="color: #0000BB">$profile</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
   <p class="para">
    This class contains a <var class="varname">type</var> field, which currently gives
    no additional functionality in the PHP driver or the database. There are
    seven predefined types, which are defined as class constants below. For
    backwards compatibility, the PHP driver uses
    <strong><code>MongoBinData::BYTE_ARRAY</code></strong> as the default; however, this
    may change to <strong><code>MongoBinData::GENERIC</code></strong> in the future.
    Users are encouraged to specify a type in
    <span class="function"><a href="mongobindata.construct.html" class="function">MongoBinData::__construct()</a></span>.
   </p>
  </div>


  <div class="section" id="mongobindata.synopsis">
   <h2 class="title">Class synopsis</h2>


   <div class="classsynopsis">
    <div class="ooclass"></div>


    <div class="classsynopsisinfo">
     <span class="ooclass">
      <strong class="classname">MongoBinData</strong>
     </span>
     {</div>

    
    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Constants */</div>
    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongobindata.html#mongobindata.constants.generic"><var class="varname">GENERIC</var></a></var><span class="initializer"> = 0</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongobindata.html#mongobindata.constants.func"><var class="varname">FUNC</var></a></var><span class="initializer"> = 1</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongobindata.html#mongobindata.constants.byte_array"><var class="varname">BYTE_ARRAY</var></a></var><span class="initializer"> = 2</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongobindata.html#mongobindata.constants.uuid"><var class="varname">UUID</var></a></var><span class="initializer"> = 3</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongobindata.html#mongobindata.constants.uuid_rfc4122"><var class="varname">UUID_RFC4122</var></a></var><span class="initializer"> = 4</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongobindata.html#mongobindata.constants.md5"><var class="varname">MD5</var></a></var><span class="initializer"> = 5</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongobindata.html#mongobindata.constants.custom"><var class="varname">CUSTOM</var></a></var><span class="initializer"> = 128</span>
    ;</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Fields */</div>
    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="type">string</span>
      <var class="varname">$<var class="varname">bin</var></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="type">int</span>
      <var class="varname">$<var class="varname">type</var></var><span class="initializer"> = 2</span>
    ;</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Methods */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="mongobindata.construct.html" class="methodname">__construct</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$type</code><span class="initializer"> = 0</span></span>)</div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="mongobindata.tostring.html" class="methodname">__toString</a></span>(): <span class="type">string</span></div>

   }</div>


  </div>


  <div class="section">
   <h2 class="title">Predefined Constants</h2>
   <div class="section" id="mongobindata.constants.types">
    <h2 class="title">Binary Data Types</h2>
    <dl>

     
      <dt id="mongobindata.constants.generic"><strong><code>MongoBinData::GENERIC</code></strong></dt>

      <dd>

       <span class="simpara">
        Generic binary data.
       </span>
      </dd>

     
     
      <dt id="mongobindata.constants.func"><strong><code>MongoBinData::FUNC</code></strong></dt>

      <dd>

       <span class="simpara">
        Function.
       </span>
      </dd>

     
     
      <dt id="mongobindata.constants.byte_array"><strong><code>MongoBinData::BYTE_ARRAY</code></strong></dt>

      <dd>

       <span class="simpara">
        Generic binary data (deprecated in favor of
        <strong><code>MongoBinData::GENERIC</code></strong>).
       </span>
      </dd>

     
     
      <dt id="mongobindata.constants.uuid"><strong><code>MongoBinData::UUID</code></strong></dt>

      <dd>

       <span class="simpara">
        Universally unique identifier (deprecated in favor of
        <strong><code>MongoBinData::UUID_RFC4122</code></strong>).
       </span>
      </dd>

     
     
      <dt id="mongobindata.constants.uuid_rfc4122"><strong><code>MongoBinData::UUID_RFC4122</code></strong></dt>

      <dd>

       <span class="simpara">
        Universally unique identifier (according to
        <a href="http://www.faqs.org/rfcs/rfc4122" class="link external">&raquo;&nbsp;RFC 4122</a>).
       </span>
      </dd>

     
     
      <dt id="mongobindata.constants.md5"><strong><code>MongoBinData::MD5</code></strong></dt>

      <dd>

       <span class="simpara">
        MD5.
       </span>
      </dd>

     
     
      <dt id="mongobindata.constants.custom"><strong><code>MongoBinData::CUSTOM</code></strong></dt>

      <dd>

       <span class="simpara">
        User-defined type.
       </span>
      </dd>

     
    </dl>

   </div>
  </div>


  <div class="simplesect">
   <h3 class="title">Changelog</h3>
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>1.5.0</td>
       <td>
        Added <strong><code>MongoBinData::GENERIC</code></strong> and
        <strong><code>MongoBinData::UUID_RFC4122</code></strong> constants.
       </td>
      </tr>

     </tbody>
    
   </table>

  </div>

 </div>

 















<h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="mongobindata.construct.html">MongoBinData::__construct</a> — Creates a new binary data object</li><li><a href="mongobindata.tostring.html">MongoBinData::__toString</a> — The string representation of this binary data object</li></ul>
</div>
</div></div></body></html>